<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="input" /><button id="btn">是否为两位数字</button>
  </body>
  <script>
    function y() {
      var input = document.getElementById("input");
      var btn = document.getElementById("btn");
      btn.onclick = function () {
        if (input.value == "") {
          return alert("不能为空！！！");
        }
        alert(
          input.value.length == 2 ? "√是两位数" : input.value.length + "位数"
        );
      };
    }
    y();
  </script>
</html>
